/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2003 Miranda ICQ/IM project, 
Copyright 2006-2009 Joe Kucera
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#include "commonheaders.h"
#include "msgs.h"


void __fastcall SAFE_FREE(void** p)
{
  if (*p)
  {
    free(*p);
    *p = NULL;
  }
}


BYTE SRMMGetSettingByte(const char *szSetting, BYTE bDef)
{
  return DBGetContactSettingByte(NULL, SRMSGMOD, szSetting, bDef);
}


WORD SRMMGetSettingWord(const char *szSetting, WORD wDef)
{
  return DBGetContactSettingWord(NULL, SRMSGMOD, szSetting, wDef);
}

DWORD SRMMGetContactSettingDword(HANDLE hContact, const char *szSetting, DWORD dwDef)
{
  return DBGetContactSettingDword(hContact, SRMSGMOD, szSetting, dwDef);
}

DWORD SRMMGetSettingDword(const char *szSetting, DWORD dwDef)
{
  return SRMMGetContactSettingDword(NULL, szSetting, dwDef);
}

int SRMMWriteSettingByte(const char *szSetting, BYTE bValue)
{
  return DBWriteContactSettingByte(NULL, SRMSGMOD, szSetting, bValue);
}

int SRMMWriteSettingWord(const char *szSetting, WORD wValue)
{
  return DBWriteContactSettingWord(NULL, SRMSGMOD, szSetting, wValue);
}

int SRMMWriteContactSettingDword(HANDLE hContact, const char *szSetting, DWORD dwValue)
{
  return DBWriteContactSettingDword(hContact, SRMSGMOD, szSetting, dwValue);
}

int SRMMWriteSettingDword(const char *szSetting, DWORD dwValue)
{
  return SRMMWriteContactSettingDword(NULL, szSetting, dwValue);
}

/* a strlennull() that likes NULL */
size_t __fastcall strlennull(const TCHAR *string)
{
  if (string)
    return lstrlen(string);

  return 0;
}

TCHAR* __fastcall SRMMTranslateT(const TCHAR* src)
{
  if (!strlennull(src))
  { // for the case of empty strings
    return _T("");
  }

  return TranslateTS(src);
}
